/**
 * Copyright (c) 2012 Nokia Corporation.
 * All rights reserved.
 *
 * For the applicable distribution terms see the license text file included in
 * the distribution.
 */

function getToken(checkUrl)
{
    var tokenRegexp = "token=(.*?)&";
    var token = "";
    
    try {
        token = checkUrl.match(tokenRegexp)[1];
    }
    catch (ex) {
        return "";
    }

    return token;
}

function getExpirationDate(checkUrl)
{
    // TODO: Get expiration time from URL. (For example, expires_in=3600
    // means expiration time is now + 3600 seconds.
    var expRegexp = "expires_in=([\w\-]+)?$/";
    var expTime = "";

    try {
        expTime = checkUrl.match(expRegexp)[1];
    }
    catch (ex) {
        console.log("exp error");
        return "";
    }

    return expTime;
}

function getParameter(checkUrl, name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec(checkUrl);
  
    if (results == null)
        return "";

    return results[1];
}
